"""
数据分析模块的数据模型
对应数据库表: dc_meter_freeze, am_alarm, dev_station, dev_box, dev_meter
"""
from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field, ConfigDict


class MeterFreeze(BaseModel):
	"""电表冻结数据模型"""
	id: int = Field(..., description="主键ID")
	serial_no: str = Field(..., max_length=24, description="电表业务编码")
	freeze_day: datetime = Field(..., description="冻结日期(UTC+8)")
	total_kwh: float = Field(..., description="当日24点累计电量")
	create_at: datetime = Field(..., description="创建时间")

	model_config = ConfigDict(from_attributes=True)


class AlarmStats(BaseModel):
	"""告警统计模型"""
	status: Optional[str] = Field(None, description="告警状态")
	alarm_type: Optional[str] = Field(None, description="告警类型")
	raised_at: Optional[datetime] = Field(None, description="告警产生时间")
	count: int = Field(0, description="数量")

	model_config = ConfigDict(from_attributes=True)


class DeviceInventory(BaseModel):
	"""设备资产统计模型"""
	total_stations: int = Field(0, description="台区总数")
	total_boxes: int = Field(0, description="电箱总数")
	total_meters: int = Field(0, description="电表总数")
	phase: Optional[str] = Field(None, description="相别")
	meter_type: Optional[str] = Field(None, description="电表类型")
	status: Optional[str] = Field(None, description="设备状态")
	count: int = Field(0, description="数量")

	model_config = ConfigDict(from_attributes=True)


class DeviceInventoryRow(BaseModel):
	"""【内部用】设备资产统计单行结果"""
	total_stations: Optional[int] = Field(None, description="台区总数")
	total_boxes: Optional[int] = Field(None, description="电箱总数")
	total_rtus: Optional[int] = Field(None, description="RTU总数")
	total_meters: Optional[int] = Field(None, description="电表总数")
	phase: Optional[str] = Field(None, description="相别 A/B/C/3P")
	meter_type: Optional[str] = Field(None, description="电表类型")
	status: Optional[str] = Field(None, description="设备状态")
	count: int = Field(0, description="该分组下的数量")

	model_config = ConfigDict(from_attributes=True)
